<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 * @author   howe <howe1995@163.com>
 */

namespace App\Model;

use function Hyperf\Config\config;

class GroupUser extends Model
{
    protected array $casts = [
        'setting' => 'json',
    ];

    public function group()
    {
        return $this->belongsTo(Group::class, 'group_id', 'id');
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }

    public function getBgFilePathAttribute($value): string
    {
        if (empty($value)) {
            return '';
        }
        if (! str_contains($value, 'http')) {
            return config('static.static_file_url') . $value;
        }
        return $value;
    }
}
